package com.jessechanrui.template;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.File;
import java.io.IOException;

/**
 * @author chenrui
 * @version 1.0
 * @description ${NAME}
 * @date 2025/10/9
 */
public class Main {
    public static void main(String[] args) {
        try {
            File filePath = new File( "F:\\test.pdf");
            //加载PDF文件
            PDDocument document = Loader.loadPDF(filePath);
            //文本剥离器
            PDFTextStripper stripper = new PDFTextStripper();
            //按位置进行排序
            stripper.setSortByPosition(true);
            //获取文本
            String text = stripper.getText(document);
            //关闭文档对象
            document.close();
            System.out.println(text);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Hello world!");
    }
}